<?php

/**
 * 分类显示
 *
 * @author Jensen
 */
class category extends AbstractAction {

    public function run() {
        global $TPL, $categoryMap;

        $cid = intval($_GET['id']);
        $page = intval($_GET['p']);
        if (empty($page)) {
            $page = 1;
        }

        $itemDAO = new BTItemsDAO();
        $items = $itemDAO->GetItemsByCategoryId($cid, PERPAGE, $page);
        // pager information
        $totalCount = $itemDAO->GetItemsCountByCategoryId($cid);
        if (debug) {
            $pager = new Pager('index.php?action=category&id=' . $cid, $totalCount, PERPAGE, $page, 'p');
        } else {
            $pager = new Pager(__CLASS__ . '?id=' . $cid, $totalCount, PERPAGE, $page, 'p');
        }

        $TPL->assign('cateName', $categoryMap[$cid]['name']);
        $TPL->assign('items', $items);
        $TPL->assign('pager', $pager->getBar());
        $TPL->display('category.tpl');
    }

}

?>
